#include "MaterialProg.h"
#include <QOpenGLContext>


MaterialProg::MaterialProg(QObject *parent)
    : QObject(parent)
    , contex(nullptr)
{}

MaterialProg::~MaterialProg()
{
    teardownGL();
}

void MaterialProg::initializeGL(QOpenGLContext *ctx, void *arg, size_t argLen)
{
    Q_UNUSED(arg)
    Q_UNUSED(argLen)

    contex = ctx;

    if (contex)
        connect(contex, SIGNAL(aboutToBeDestroyed()), SLOT(teardownGL()));
}

void MaterialProg::setMaterial(const Material &material)
{
    material_ = material;
    emit dataChanged();
}

void MaterialProg::teardownGL()
{
    if (contex) {
        disconnect(contex, SIGNAL(aboutToBeDestroyed()), this, SLOT(teardownGL()));
        contex = nullptr;
    }
}
